package wgff.xml
{
	import flash.events.*;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	
	public class globalXml extends EventDispatcher
	{
		import mx.controls.Alert;
		
		public var httpService:URLLoader;
		public var xml:XML;
		public var bytesLoaded:Number = 0;
		public var bytesTotal:Number = 0;
		public var percentLoaded:Number = 0;
		
		public function globalXml()
		{
			this.httpService = new URLLoader();
			//this.httpService.addEventListener(FaultEvent.FAULT, errorXML);
			//this.httpService.addEventListener(Event.ACTIVATE, progressXML);
			this.httpService.addEventListener(Event.COMPLETE, getXML);
			//this.httpService.addEventListener(ProgressEvent.PROGRESS, progressXML);
		}
		
		public function sendXML(url:String):void {
			this.bytesLoaded = 0;
			this.bytesTotal = 0;
			this.percentLoaded = 0;
			this.httpService.load(new URLRequest(url));
		}
		
		public function getXML(e:Event):void {
			this.xml = this.httpService.data as XML;
			dispatchEvent(new Event(Event.COMPLETE));
		}
		
		/*
		public function errorXML(e:FaultEvent):void {
			Alert.show(e.message.toString());
			dispatchEvent(new Event(FaultEvent.FAULT));
		}
		//*/
		
		private function progressXML(event:ProgressEvent):void
        {
            this.bytesLoaded = this.httpService.bytesLoaded;
            this.bytesTotal = this.httpService.bytesTotal;
            this.percentLoaded = Math.round((this.httpService.bytesTotal * 100) / this.httpService.bytesLoaded);
        }

	}
}